package com.student.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.student.VO.PageInfoResult;
import com.student.dto.ResponseDto;
import com.student.mapper.VenuesMapper;
import com.student.pojo.Artists;
import com.student.pojo.VenueReser;
import com.student.pojo.Venues;
import com.student.service.VenuesService;
import com.student.util.PageResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongsProject: SupportGroup
 * @BelongsPackage: com.student.service.impl
 * @Author: 小徐
 * @CreateTime: 2025-02-28 16:07
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class VenuesServiceImpl implements VenuesService {
    @Autowired
    private VenuesMapper venuesMapper;


    @Override
    public ResponseDto getAllVenues(Venues venues) {
        //        mybatis自带的分页插件，按照名字做排序
        PageHelper.startPage(venues.getCurrentPage(), venues.getPageSize());
        List<Venues> snackGoodsCates = venuesMapper.getAllVenues(venues);

        PageInfo<Venues> cyCardPageInfo = new PageInfo<>(snackGoodsCates);

        PageInfoResult result = PageResultUtils.getResult(cyCardPageInfo);

        System.out.println(result);
        return ResponseDto.success(result);
    }

    @Override
    public ResponseDto addVenues(Venues venues) {
        Integer res = venuesMapper.addVenues(venues);
        if (res > 0) {
            return ResponseDto.success(res);
        }
        return ResponseDto.error(null);
    }

    @Override
    public ResponseDto updateVenues(Venues venues) {
        Integer res = venuesMapper.updateVenues(venues);
        if (res > 0) {
            return ResponseDto.success(res);
        }
        return ResponseDto.error(null);
    }

    @Override
    public ResponseDto deleteVenues(Integer id) {
        Integer res = venuesMapper.deleteVenues(id);
        if (res > 0) {
            return ResponseDto.success(res);
        }
        return ResponseDto.error(null);
    }

    @Override
    public ResponseDto getAllVenuesMessage() {
        List<Venues> venues = venuesMapper.getAllVenuesMessage();
        if (venues.size() > 0) {
            return ResponseDto.success(venues);
        }
        return ResponseDto.error(null);
    }

    @Override
    public ResponseDto addBooking(String idCard, Integer id, String phone, Integer venuesId, Integer artistId,Integer titleId) {
        VenueReser venueReser = venuesMapper.selectUser(id, venuesId, artistId);
        if (venueReser == null) {
            Integer res = venuesMapper.addBooking(idCard, id, phone, venuesId, artistId,titleId);
            if (res > 0) {
                return ResponseDto.success(null);
            }

        } else {
            return new ResponseDto(2, "已经预约过了", null);
        }
        return ResponseDto.error(null);
    }

    @Override
    public ResponseDto getAllVenuesUserMessage(VenueReser venueReser) {
        //        mybatis自带的分页插件，按照名字做排序
        PageHelper.startPage(venueReser.getCurrentPage(), venueReser.getPageSize());
        List<VenueReser> snackGoodsCates = venuesMapper.getAllVenuesUserMessage(venueReser);

        PageInfo<VenueReser> cyCardPageInfo = new PageInfo<>(snackGoodsCates);

        PageInfoResult result = PageResultUtils.getResult(cyCardPageInfo);

        System.out.println(result);
        return ResponseDto.success(result);
    }
}